﻿	      <?php include("conn.php");
             mysql_query('SET NAMES UTF8'); 

	  

class MyPrizeBean
{
	
	public $images;
	public $shopid;
	public $title;
	public $distance;
	public $evaluate;
	public $reply;
	public $like;
	
	function __construct($images,$shopid,$title,$distance,$evaluate,$reply,$like)
	{
		
		$this->images      = $images;
		$this->shopid      = $shopid;
		$this->title      = $title;
		$this->distance      = $distance;
		$this->evaluate      = $evaluate;
		$this->reply      = $reply;
		$this->like      = $like;
	
	}
}


if($_REQUEST['page']!="")
{
$de=$_REQUEST['page']*$_REQUEST['pagesize'];
$size=$_REQUEST['pagesize'];
}

else
{
$de=0;
$size=5;
}
   function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
    $theta = $longitude1 - $longitude2;
    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $miles = acos($miles);
    $miles = rad2deg($miles);
    $miles = $miles * 60 * 1.1515;
    $kilometers = $miles * 1.609344;
    return compact('kilometers'); 

}

   $rert31=mysql_query("select * from shop where city like '".$_REQUEST[city]."%' order by  shopid desc limit $de,$size");
  $prize = array();
  
 while($rowf=mysql_fetch_array($rert31))
 {
  
     $rert32=mysql_query("select * from user where userid='".$_REQUEST[userid]."'");
     $rowf3=mysql_fetch_array($rert32);

       $longitude1=$rowf3['longitude'];$latitude1=$rowf3['latitude'];$longitude2=$rowf['longitude'];$latitude2=$rowf['latitude'];
	   
	

$distance = getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2);
foreach ($distance as $unit => $value) {
    $dic= number_format($value,1);
}

if($_REQUEST[userid]!="")
{
$juli=$dic;
}
else
{
$juli=0;
}

$counts=mysql_query("select SUM(service) from goodsreply  where   shopid ='".$rowf['shopid']."'");

//评论数
$rss=mysql_fetch_array($counts);
$sum=$rss[0];



$count=mysql_query("select count(*) from goodsreply  where   shopid ='".$rowf['shopid']."'");

//评论数
$rs=mysql_fetch_array($count);
$totalNumber=$rs[0];
$ping=round(($sum/$totalNumber),2);

$count1=mysql_query("select count(*) from like  where   shopid ='".$rowf['shopid']."'");

//点赞数
$rs1=mysql_fetch_array($count1);
$totalNumber1=$rs1[0];





   
		$prize[] = new MyPrizeBean($rowf['images'],$rowf['shopid'],$rowf['name'],$juli,$ping,$$totalNumber,$totalNumber1);
		
	}

echo json_encode($prize);


?>